﻿/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
#region Using directives

using System;
using System.Collections;
using System.Text;
using ELE.EnterpriseLibrary.Naming.Spi;
using ELE.EnterpriseLibrary.Naming.Configuration;
using ELE.Common.Util;

#endregion

namespace ELE.EnterpriseLibrary.Naming.Factories
{
  /// <summary>
  /// General context factory
  /// </summary>
	public class DefaultNamingContextFactory : IInitialContextFactory
	{
    /// <summary>
    /// Default Contructor
    /// </summary>
		public DefaultNamingContextFactory()
		{			
		}

    #region IInitialContextFactory Members
    /// <summary>
    /// Creates an initial context based on a set of environment properties
    /// </summary>
    /// <param name="environment"></param>
    /// <returns></returns>
    public INamingContext GetInitialContext(System.Collections.Hashtable environment)
    {
      if (environment != null)
      {
        string configFile = (string)environment[InitialContext.CONTEXT_SETTINGS_KEY_NAME];
        if (StringUtils.NotEmpty( configFile ))
        {
          InitialContext ctx = new InitialContext(configFile);
          return ctx;
        }
      }
      return null;
    }

    #endregion
  }
}
